package com.ruoyi.system.controller;

import java.util.ArrayList;
import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.QZxjk;
import com.ruoyi.system.service.IQZxjkService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 坐席监控Controller
 * 
 * @author ruoyi
 * @date 2024-06-27
 */
@Controller
@RequestMapping("/system/zxjk")
public class QZxjkController extends BaseController
{
    private String prefix = "system/zxjk";

    @Autowired
    private IQZxjkService qZxjkService;

    @RequiresPermissions("system:zxjk:view")
    @GetMapping()
    public String zxjk()
    {
        return prefix + "/zxjk";
    }

    /**
     * 查询坐席监控列表
     */
    @RequiresPermissions("system:zxjk:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(QZxjk qZxjk)
    {
        startPage();
        List<QZxjk> list = qZxjkService.selectQZxjkList(qZxjk);

        List<QZxjk> listRes = new ArrayList<QZxjk>();

        for (QZxjk zx: list ){

            if (zx.getJnz().equals("1")){
                zx.setJnz("默认小组");
            }else if  (zx.getJnz().equals("0")){
                zx.setJnz("电话销售");
            }
            listRes.add(zx);

        }
        return getDataTable(listRes);
    }



    @PostMapping("/hjjk")
    @ResponseBody
    public TableDataInfo hjjk(QZxjk qZxjk)
    {
        startPage();
        List<QZxjk> list = qZxjkService.selectQZxjkList(qZxjk);

        List<QZxjk> listRes = new ArrayList<QZxjk>();

        for (QZxjk zx: list ){

            if (zx.getJnz().equals("1")){
                zx.setJnz("默认小组");
            }else if  (zx.getJnz().equals("0")){
                zx.setJnz("电话销售");
            }
            listRes.add(zx);

        }
        return getDataTable(listRes);
    }


    @PostMapping("/imjk")
    @ResponseBody
    public TableDataInfo imjk(QZxjk qZxjk)
    {
        startPage();
        List<QZxjk> list = qZxjkService.selectQZxjkList(qZxjk);

        List<QZxjk> listRes = new ArrayList<QZxjk>();

        for (QZxjk zx: list ){

            if (zx.getJnz().equals("1")){
                zx.setJnz("默认小组");
            }else if  (zx.getJnz().equals("0")){
                zx.setJnz("电话销售");
            }
            listRes.add(zx);

        }
        return getDataTable(listRes);
    }


    /**
     * 导出坐席监控列表
     */
    @RequiresPermissions("system:zxjk:export")
    @Log(title = "坐席监控", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(QZxjk qZxjk)
    {
        List<QZxjk> list = qZxjkService.selectQZxjkList(qZxjk);
        ExcelUtil<QZxjk> util = new ExcelUtil<QZxjk>(QZxjk.class);
        return util.exportExcel(list, "坐席监控数据");
    }

    /**
     * 新增坐席监控
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存坐席监控
     */
    @RequiresPermissions("system:zxjk:add")
    @Log(title = "坐席监控", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(QZxjk qZxjk)
    {
        return toAjax(qZxjkService.insertQZxjk(qZxjk));
    }

    /**
     * 修改坐席监控
     */
    @RequiresPermissions("system:zxjk:edit")
    @GetMapping("/edit/{zxjkId}")
    public String edit(@PathVariable("zxjkId") Long zxjkId, ModelMap mmap)
    {
        QZxjk qZxjk = qZxjkService.selectQZxjkByZxjkId(zxjkId);
        mmap.put("qZxjk", qZxjk);
        return prefix + "/edit";
    }

    /**
     * 修改保存坐席监控
     */
    @RequiresPermissions("system:zxjk:edit")
    @Log(title = "坐席监控", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(QZxjk qZxjk)
    {
        return toAjax(qZxjkService.updateQZxjk(qZxjk));
    }

    /**
     * 删除坐席监控
     */
    @RequiresPermissions("system:zxjk:remove")
    @Log(title = "坐席监控", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(qZxjkService.deleteQZxjkByZxjkIds(ids));
    }
}
